<?php

namespace app\admin\model\vppz;

use think\Model;
use think\Db;
use traits\model\SoftDelete;

class FamilyMembers extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'vppz_family';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

// 追加属性
    protected $append = [
		'avator_url',	// 需在此处追加属性，才会触发获取器 getPicImageUrlAttr
		'background_url',	// 需在此处追加属性，才会触发获取器 getPicImageUrlAttr
        'sex_text'
    ];
// 获取器直接转换url
	public function getAvatorUrlAttr($value,$data)
    {
        return \addons\vppz\library\Vpower::dourl($data['avator']);
    }
	public function getBackgroundUrlAttr($value,$data)
    {
        return \addons\vppz\library\Vpower::dourl($data['background']);
    }
    public function getsexList()
    {
        return ['1'=>__('sex 1'),'2'=>__('sex 2'),'3'=>__('sex 3')];
    }
    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getsexList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
